
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class ShareUserNote
	{
	
		
	
		#region Member Variables

		private int intNoteID = int.MinValue;
		private string strNoteTitle = string.Empty;
		private string strNoteContent = string.Empty;
		private string strNotePicture = string.Empty;
		private bool bolIsShareAll;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "ShareUserNote_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// NoteID
		/// 
		/// </summary>
		public int NoteID
		{
			get { return  intNoteID; }
			set { intNoteID = value; }
		}

		/// <summary>
		/// NoteTitle
		/// 
		/// </summary>
		public string NoteTitle
		{
			get { return  strNoteTitle; }
			set { strNoteTitle = value; }
		}

		/// <summary>
		/// NoteContent
		/// 
		/// </summary>
		public string NoteContent
		{
			get { return  strNoteContent; }
			set { strNoteContent = value; }
		}

		/// <summary>
		/// NotePicture
		/// 
		/// </summary>
		public string NotePicture
		{
			get { return  strNotePicture; }
			set { strNotePicture = value; }
		}

		/// <summary>
		/// IsShareAll
		/// 
		/// </summary>
		public bool IsShareAll
		{
			get { return  bolIsShareAll; }
			set { bolIsShareAll = value; }
		}


		#endregion		
		
		
		#region Constructor

		public ShareUserNote()
		{
		}
		private static ShareUserNote _current;
		static ShareUserNote()
		{
			_current = new ShareUserNote();
		}
		public static ShareUserNote Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserNote_Select");
				objData.AddParameter("@NoteID", this.NoteID);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["NoteID"]))	this.NoteID = Convert.ToInt32(reader["NoteID"]);
					if(!this.IsDBNull(reader["NoteTitle"]))	this.NoteTitle = Convert.ToString(reader["NoteTitle"]);
					if(!this.IsDBNull(reader["NoteContent"]))	this.NoteContent = Convert.ToString(reader["NoteContent"]);
					if(!this.IsDBNull(reader["NotePicture"]))	this.NotePicture = Convert.ToString(reader["NotePicture"]);
					if(!this.IsDBNull(reader["IsShareAll"]))	this.IsShareAll = Convert.ToBoolean(reader["IsShareAll"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : Share_UserNote
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserNote_Insert");
				if(this.NoteID != int.MinValue) objData.AddParameter("@NoteID", this.NoteID);
				objData.AddParameter("@NoteTitle", this.NoteTitle);
				objData.AddParameter("@NoteContent", this.NoteContent);
				objData.AddParameter("@NotePicture", this.NotePicture);
				objData.AddParameter("@IsShareAll", this.IsShareAll);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : Share_UserNote
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserNote_Update");
				if(this.NoteID != int.MinValue)	objData.AddParameter("@NoteID", this.NoteID);
				else objData.AddParameter("@NoteID", DBNull.Value);
				objData.AddParameter("@NoteTitle", this.NoteTitle);
				objData.AddParameter("@NoteContent", this.NoteContent);
				objData.AddParameter("@NotePicture", this.NotePicture);
				objData.AddParameter("@IsShareAll", this.IsShareAll);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : Share_UserNote
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserNote_Delete");
				objData.AddParameter("@NoteID", this.NoteID);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : Share_UserNote
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserNote_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	Share_UserNote objShare_UserNote = new Share_UserNote();
			objShareUserNote.NoteID = txtNoteID.Text;
			objShareUserNote.NoteTitle = txtNoteTitle.Text;
			objShareUserNote.NoteContent = txtNoteContent.Text;
			objShareUserNote.NotePicture = txtNotePicture.Text;
			objShareUserNote.IsShareAll = txtIsShareAll.Text;

		 
		 ******************************************************
		 
		 			txtNoteID.Text = objShareUserNote.NoteID;
			txtNoteTitle.Text = objShareUserNote.NoteTitle;
			txtNoteContent.Text = objShareUserNote.NoteContent;
			txtNotePicture.Text = objShareUserNote.NotePicture;
			txtIsShareAll.Text = objShareUserNote.IsShareAll;

		 
		*******************************************************/
		
	}
}
